<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">
      <div class="table-page-search-wrapper" v-if="hasPerm('appReport:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="4" :sm="24">
              <a-form-item label="被举报人">
                <a-input v-model="queryParam.otherUser" allow-clear placeholder="请输入被举报人"/>
              </a-form-item>
            </a-col>
            <a-col :md="4" :sm="24">
              <a-form-item label="举报人">
                <a-input v-model="queryParam.ownUser" allow-clear placeholder="请输入举报人"/>
              </a-form-item>
            </a-col>
              <a-col :md="4" :sm="24">
                <a-form-item label="处理状态">
                  <a-select v-model="queryParam.status" alow-clear placeholder="请选择状态" >
                    <a-select-option v-for="(item,index) in reportStatusDict" :key="index" :value="item.code" >{{ item.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            <a-col :md="8" :sm="24" >
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :rowKey="(record) => record.id"
      >
        <span slot="status" slot-scope="text">
          {{ 'report_status' | dictType(text) }}
        </span>
        <span slot="action" slot-scope="text, record">
          <a v-if="hasPerm('appReport:edit')" @click="$refs.editForm.edit(record)">编辑</a>
        </span>
      </s-table>
      <edit-form ref="editForm" @ok="handleOk" />
    </a-card>
  </div>
</template>
<script>
  import { STable, XDown } from '@/components'
  import { appReportPage } from '@/api/modular/app/report/appReportManage'
  import editForm from './editForm.vue'
  export default {
    components: {
      STable,
      editForm,
      XDown
    },
    data () {
      return {
        // 查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '被举报人',
            align: 'center',
            dataIndex: 'otherUser'
          },
          {
            title: '举报人',
            align: 'center',
            dataIndex: 'ownUser'
          },
          {
            title: '举报内容',
            align: 'center',
            dataIndex: 'message'
          },
          {
            title: '处理状态',
            align: 'center',
            dataIndex: 'status',
            scopedSlots: { customRender: 'status' }
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return appReportPage(Object.assign(parameter, this.queryParam)).then((res) => {
            return res.data
          })
        },
        reportStatusDict: []
      }
    },
    created () {
      if (this.hasPerm('appReport:edit')) {
        this.columns.push({
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        })
      }
      // 初始化字典下来
      this.sysDictTypeDropDown()
    },
    methods: {
      /**
       * 获取字典数据
       */
      sysDictTypeDropDown () {
        this.reportStatusDict = this.$options.filters['dictData']('report_status')
      },
      handleOk () {
        this.$refs.table.refresh()
      }
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
